package com.app.web.order.job;

import com.alibaba.fastjson.JSON;
import com.app.utils.base.j2se.*;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description  订单分佣明细
 * Created by 王伟
 * Date create on 15:28 2019/12/12.
 */
@Component
public class OrderPromotionDetails implements Job {
    @Autowired
    private OrderAnalyService orderAnalyService;

    //源表 基础数据表
    public String source_t_goods_order="t_goods_order";
    //分析表 订单分佣明细表
    public String analy_order_promotion_details="t_analy_order_promotion_details";

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        analy();
    }

    public void analy(){
        System.out.println("*****begin*****"+ DateUtil.getDatetime()+"-分析处理用户订单分佣明细数据-OrderPromotionDetails");
        long record = 0;
        try{
            //获取记录值
            record = orderAnalyService.getRecord(source_t_goods_order, analy_order_promotion_details);
            //获取订单数据
            List<Map<String, Object>> orderList = orderAnalyService.getGoodsOrderListByRecord(record);
            //更新分佣明细
            if(Common.isNotEmpty(orderList))orderAnalyService.updateUserMoney(orderList,source_t_goods_order, analy_order_promotion_details);
        }catch (Exception e){
            Map<String,Object> map = new HashMap<>();
            map.put("module",this.getClass().getName());
            map.put("methods",Thread.currentThread().getStackTrace()[1].getMethodName());
            map.put("desc","分析处理用户订单分佣明细数据");
            map.put("json","记录值="+record);
//            map.put("exce", Logger.exceptionToString(e));
            /* TODO 发送钉钉推送 */
//            logService.taskLog(map);
            Logger.error(String.format("分析处理用户订单分佣明细数据异常，param:%s", JSON.toJSONString(map)),e);
            throw new RuntimeException("分析处理用户分佣明细数据异常");
        }
        System.out.println("*****end*****"+ DateUtil.getDatetime()+"-分析处理用户订单分佣明细数据-OrderPromotionDetails");
        System.out.println();
    }
}
